using WebApplication1;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
OrderService orderService = new OrderService();
app.MapGet("/", () => "Hello Order Service!");

app.MapGet("/orderitems", () => Results.Json(orderService.orders));

app.MapGet("/orderitems/{id}", (int id) =>
{
    if (orderService.IfExist(id) != null)
        return Results.Json(orderService.IfExist(id));
    return Results.NotFound();
});

app.MapPost("/orderitems", (Order order) =>
{
    order.Id = orderService.count + 1;
    orderService.AddOrder(order);
    
    return Results.Json(orderService.orders);
});


app.MapPut("/orderitems/{id}", (int id, Order inputOrder) =>
{
    if(orderService.ChangeOrder(inputOrder,id))
        return Results.NoContent();
    return Results.NotFound();
});

app.MapDelete("/orderitems/{id}", (int id) =>
{
    if (orderService.DeleteOrder(id))
        return Results.NoContent();
    return Results.NotFound();
});

app.Run();

